<template>
  <view class="thinking-loader-overlay" v-if="visible">
    <view class="thinking-loader-container">
      <view class="thinking-text">
        <text 
          v-for="(char, index) in chars" 
          :key="index"
          class="thinking-char"
          :style="{ animationDelay: (index * 0.1) + 's' }"
        >
          {{ char }}
        </text>
      </view>
      <view class="thinking-dots">
        <view class="dot" :style="{ animationDelay: '0s' }"></view>
        <view class="dot" :style="{ animationDelay: '0.2s' }"></view>
        <view class="dot" :style="{ animationDelay: '0.4s' }"></view>
        <view class="dot" :style="{ animationDelay: '0.6s' }"></view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'ThinkingLoader',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    text: {
      type: String,
      default: '正在思考中'
    }
  },
  computed: {
    chars() {
      return this.text.split('')
    }
  }
}
</script>

<style lang="scss" scoped>
.thinking-loader-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.thinking-loader-container {
  background-color: #2a304d;
  border-radius: 20rpx;
  padding: 60rpx 80rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40rpx;
}

.thinking-text {
  display: flex;
  align-items: center;
  gap: 4rpx;
}

.thinking-char {
  display: inline-block;
  font-size: 32rpx;
  color: #4e5eff;
  font-weight: bold;
  animation: bounce 2s infinite;
}

.thinking-dots {
  display: flex;
  gap: 12rpx;
  align-items: center;
}

.dot {
  width: 12rpx;
  height: 12rpx;
  border-radius: 50%;
  background-color: #8a8a9a;
  animation: bounce 1.5s infinite;
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-15rpx);
  }
  60% {
    transform: translateY(-8rpx);
  }
}
</style>